<template>
    <!-- 添加或修改请购单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="24">
                            <el-form-item label="驳回原因" prop="reason">
                                <el-input v-model="form.reason"  type="textarea"  placeholder="请输入驳回原因"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "LvdoBohuiForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/lvDo/lvDo/',
                    editReject:'/lvDo/lvDo/editReject',
                },
            };
        },
        created() {
        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                  id: null,
                  delFlag: null,
                  createBy: null,
                  createTime: null,
                  updateBy: null,
                  updateTime: null,
                  remark: null,
                  code: null,
                  name: null,
                  mainId: null,
                  nos: null,
                  ddDate: null,
                  subDate: null,
                  type: null,
                  ywType: null,
                  tax: null,
                  customerId: null,
                  customerName: null,
                  isBuy: null,
                  money: null,
                  dingjin: null,
                  shengyu: null,
                  shuie: null,
                  counts: null,
                  dunwei: null,
                  supplierId: null,
                  supplierName: null,
                  deptId: null,
                  deptName: null,
                  userId: null,
                  userName: null,
                  state: null,
                  linkman: null,
                  linktel: null,
                  idcard: null,
                  moneycard: null,
                  reason: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加请购单";
            },
            /** 修改按钮操作 */
            showBohui(id,status) {
                this.reset();
                this.form.id = id;
                this.form.status = status;
                this.open = true;
                this.title = "驳回原因";
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.editReject, this.form).then(response => {
                                this.$modal.msgSuccess("驳回成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
